<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改数据集')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-app01Dataset-edit" th:object="${app01Dataset}">
        <input id="id" name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">数据集名称：</label>
            <div class="col-sm-8">
                <input id="name" name="name" th:field="*{name}" class="form-control" type="text">
            </div>
        </div>
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">训练集数量：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input id="numTrain" name="numTrain" th:field="*{numTrain}" class="form-control" type="text">-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">验证集数量：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input id="numVall" name="numVall" th:field="*{numVall}" class="form-control" type="text">-->
<!--            </div>-->
<!--        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">高：</label>
            <div class="col-sm-8">
                <input id="height" name="height" th:field="*{height}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">宽：</label>
            <div class="col-sm-8">
                <input id="width" name="width" th:field="*{width}" class="form-control" type="text">
            </div>
        </div>
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">上传时间：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input id="uploadTime" name="uploadTime" th:field="*{uploadTime}" class="form-control" type="text">-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">归属用户：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input id="userId" name="userId" th:field="*{userId}" class="form-control" type="text">-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">数据集地址：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input id="location" name="location" th:field="*{location}" class="form-control" type="text">-->
<!--            </div>-->
<!--        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">是否公开：</label>
            <div class="col-sm-8">
<!--                下拉框是或否-->
                <select id="isPublic" name="isPublic" th:field="*{isPublic}" class="form-control">
                    <option value="1">是</option>
                    <option value="0">否</option>
                </select>
<!--                <input id="isPublic" name="isPublic" th:field="*{isPublic}" class="form-control" type="text">-->
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    var prefix = ctx + "deep_learning/app01Dataset";
    $("#form-app01Dataset-edit").validate({
        rules: {
            xxxx: {
                required: true,
            },
        },
        focusCleanup: true
    });

    // console.log($('#form-app01Dataset-edit').serialize())
    // 打印id
    // console.log($('#id').val())

    // 记录修改前后的高和宽，有变化再进行图片的resize操作
    var oldHeight = $('#height').val();
    var oldWidth = $('#width').val();
    console.log(oldHeight, oldWidth)



    // 表单提交事件
    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-app01Dataset-edit').serialize());
            // ajax提交表单发送id到后端，根据id查询对应数据，如果高和宽有变化，进行图片的resize操作
            if (oldHeight!= $('#height').val() || oldWidth!= $('#width').val()) {
                console.log('图片尺寸有变化，进行resize操作')
                console.log($('#height').val(), $('#width').val())
                var formData = new FormData();
                formData.append('id', $('#id').val());
                formData.append('height', $('#height').val());
                formData.append('width', $('#width').val());
                $.ajax({
                    url: prefix + "/resizePicture", // 后端控制器的请求路径
                    type: 'POST',
                    data: formData,
                    processData: false,
                    contentType: false,
                    success: function (response) {
                        console.log(response);
                    },
                    error: function (xhr, status, error) {
                        console.error('请求失败:', error);
                    }
                });
            }
            // window.parent.postMessage('refreshTable', '*');
        }
    }
</script>
</body>
</html>
